package course.service.impl;

import course.dao.CollegeDao;
import course.dao.impl.CollegeDaoImpl;
import course.pojo.entity.College;
import course.pojo.vo.Page;
import course.service.CollegeService;
import course.utils.JDBCUtil;

import java.sql.Connection;
import java.util.List;

/**
 * @author HLF
 * @date 2022/6/30 20:23
 */
public class CollegeServiceImpl implements CollegeService {
    private CollegeDao collegeDao = new CollegeDaoImpl();

    @Override
    public College getById(Integer cid) {
        Connection connection = JDBCUtil.getConnection();
        College college = collegeDao.getById(cid, connection);
        JDBCUtil.closeConnection(connection);
        return college;
    }

    @Override
    public int addCollege(College college) {
        Connection connection = JDBCUtil.getConnection();
        int i = collegeDao.addCollege(college, connection);
        JDBCUtil.closeConnection(connection);
        return i;
    }

    @Override
    public int updateById(College college) {
        Connection connection = JDBCUtil.getConnection();
        int i = collegeDao.updateById(college, connection);
        JDBCUtil.closeConnection(connection);
        return i;
    }

    @Override
    public int deleteById(Integer cid) {
        Connection connection = JDBCUtil.getConnection();
        int i = collegeDao.deleteById(cid, connection);
        JDBCUtil.closeConnection(connection);
        return i;
    }

    @Override
    public List<College> getList() {
        Connection connection = JDBCUtil.getConnection();
        List<College> list = collegeDao.getList(connection);
        JDBCUtil.closeConnection(connection);
        return list;
    }

    @Override
    public int deleteSelect(List<Integer> ids) {
        Connection connection = JDBCUtil.getConnection();
        int i = collegeDao.deleteSelect(ids, connection);
        JDBCUtil.closeConnection(connection);
        return i;
    }

    @Override
    public long count() {
        Connection connection = JDBCUtil.getConnection();
        long count = collegeDao.count(connection);
        JDBCUtil.closeConnection(connection);
        return count;
    }

    @Override
    public Page<College> page(Integer pageNo) {
        Connection connection = JDBCUtil.getConnection();
        Page<College> page = collegeDao.page(pageNo, connection);
        JDBCUtil.closeConnection(connection);
        return page;
    }

    @Override
    public Page<College> query(String cname, Integer pageNo) {
        Connection connection = JDBCUtil.getConnection();
        Page<College> page = collegeDao.query(cname, pageNo, connection);
        JDBCUtil.closeConnection(connection);
        return page;
    }

    @Override
    public College getByCname(String cname) {
        Connection connection = JDBCUtil.getConnection();
        College college = collegeDao.getByCname(cname, connection);
        JDBCUtil.closeConnection(connection);
        return college;
    }

    @Override
    public List<College> selectBathByIds(List<Integer> ids) {
        Connection connection = JDBCUtil.getConnection();
        List<College> colleges = collegeDao.selectBathByIds(ids, connection);
        JDBCUtil.closeConnection(connection);
        return colleges;
    }
}
